package com.dataiti.sgsl.layer;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.GeneralPath;
import java.awt.geom.Line2D;

import sun.awt.geom.Curve;

import com.jhlabs.map.AngleFormat;
import com.jhlabs.map.ProjectionPainter;
import com.jhlabs.map.layer.Layer;
import com.jhlabs.map.layer.MapGraphics;
import com.jhlabs.map.proj.Projection;

public class editlayer extends Layer {
	
	private String type;
	private float startLongtitude;
	private float startLatitude;
	private float endLongtitude;
	private float endLatitude;
	private float radius;	
	private Color objColor;
	
	public editlayer(float startLongtitude,float startLatitude,double radius2,String type,Color objColor)
	{
		this.startLatitude = startLatitude;
		this.startLongtitude = startLongtitude;
		this.radius = (float) radius2;	
		this.type = type;
		this.objColor = objColor;		
	}
	
	public editlayer(float startLongtitude,float startLatitude,float endLongtitude,float endLatitude,String type,Color objColor)
	{
		this.startLatitude = startLatitude;
		this.startLongtitude = startLongtitude;
		this.endLatitude = endLatitude;
		this.endLongtitude = endLongtitude;
		this.type = type;
		this.objColor = objColor;		
	}
	
	
	
	public void paintLayer( MapGraphics objGraphics ) {
		
		if (type.equals(SGSLConstants.CMD_CIRCLE))
		{
			 drawCircle(objGraphics);
		}
		else if (type.equals(SGSLConstants.CMD_LINE))
		{
			drawArc(objGraphics);
		}			
		
	}



	public float getLatitude() {
		return startLatitude;
	}



	public void setLatitude(float latitude) {
		this.startLatitude = latitude;
	}



	public float getLongtitude() {
		return startLongtitude;
	}



	public void setLongtitude(float longtitude) {
		this.startLongtitude = longtitude;
	}



	public double getRadius() {
		return radius;
	}



	public void setRadius(double radius) {
		this.radius = (float) radius;
	}



	public String getType() {
		return type;
	}



	public void setType(String type) {
		this.type = type;
	}



	public float getEndLatitude() {
		return endLatitude;
	}



	public void setEndLatitude(float endLatitude) {
		this.endLatitude = endLatitude;
	}



	public float getEndLongtitude() {
		return endLongtitude;
	}
	
	public void setEndLongtitude(float endLongtitude) {
		this.endLongtitude = endLongtitude;
	}
	
	public void drawCircle( MapGraphics objGraphics)
	{
		Graphics2D g2d = objGraphics.getGraphics2D();		
		Projection projection =objGraphics.getProjection();
		
		ProjectionPainter pp = ProjectionPainter.getProjectionPainter( projection );
		g2d.setPaint( objColor);
		
		GeneralPath gc = new GeneralPath();
		ProjectionPainter.smallCircle( startLongtitude, startLatitude, radius, 180, gc, true );
		gc.closePath();
		pp.drawPath( g2d, gc, objColor,null);	
	}
	
	public void drawArc( MapGraphics objGraphics)
	{
		Graphics2D g2d = objGraphics.getGraphics2D();
        Projection projection =objGraphics.getProjection();		
		ProjectionPainter pp = ProjectionPainter.getProjectionPainter( projection );
		g2d.setPaint(objColor);
		GeneralPath line = new GeneralPath();				
		line.moveTo( startLongtitude,startLatitude);
		
		line.lineTo( endLongtitude,endLatitude );		
	
		Shape arc = pp.projectPath( line, null, false );
		
		if ( arc != null )
			g2d.draw( arc );
		
	}

	public Color getObjColor() {
		return objColor;
	}
	
	public void setObjColor(Color objColor) {
		this.objColor = objColor;
	}

}
